package Array;

public class yanghui {
    public static int[][] getyanghui(int n){
        int[][] yanghui = new int[n][n];
        for (int i=0;i<n;i++){
            for (int j=0;j<=i;j++){
                if (i==0||j==0||j==i)yanghui[i][j]=1;
                else yanghui[i][j]=yanghui[i-1][j-1]+yanghui[i-1][j];
            }
        }
        return yanghui;
    }


    public static void main(String[] args) {
        int row = 6;
        int[][] getyanghui = getyanghui(row);
        for (int i=0;i<getyanghui.length;i++) {
            for (int j=0;j<=row-i;j++){
                System.out.print(" ");
            }
            for (int j=0;j<=i;j++){
                System.out.printf("%2d",getyanghui[i][j]);
            }
            System.out.println();
        }
    }
}
